﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace TARADesktopDoctor
{
    /// <summary>
    /// Interaction logic for HumanBody.xaml
    /// </summary>
    public partial class HumanBody : UserControl
    {
        tara_wcf.ItaraServiceClient svc = new tara_wcf.ItaraServiceClient();
        
        public HumanBody()
        {
            this.InitializeComponent();
            
            //BackgroundWorker bgWorker = new BackgroundWorker();
            //bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
            //bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);
            //bgWorker.WorkerSupportsCancellation = true;

            //run background worker
            //bgWorker.RunWorkerAsync(500);
        }

        public void doWork()
        {
            #region forloopjointList to highlight joint with impairment
            foreach (KeyValuePair<int, int> temp in MainPage.jointList)
            {
                switch (temp.Key)
                {
                    case 1:
                        btnNeck.Background = Brushes.Red;
                        break;
                    case 2:
                        btnLeftShoulder.Background = Brushes.Red;
                        break;
                    case 3:
                        btnRightShoulder.Background = Brushes.Red;
                        break;
                    case 4:
                        btnLeftElbow.Background = Brushes.Red;
                        break;
                    case 5:
                        btnRightElbow.Background = Brushes.Red;
                        break;
                    case 6:
                        btnLeftWrist.Background = Brushes.Red;
                        break;
                    case 7:
                        btnRightWrist.Background = Brushes.Red;
                        break;
                    case 9:
                        btnLeftHip.Background = Brushes.Red;
                        break;
                    case 10:
                        btnRightHip.Background = Brushes.Red;
                        break;
                    case 11:
                        btnLeftKnee.Background = Brushes.Red;
                        break;
                    case 12:
                        btnRightKnee.Background = Brushes.Red;
                        break;
                    case 13:
                        btnLeftAnkle.Background = Brushes.Red;
                        break;
                    case 14:
                        btnRightAnkle.Background = Brushes.Red;
                        break;
                }
            }
            #endregion
        }

        //void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        //{
        //    #region forloopjointList to highlight joint with impairment
        //    foreach (KeyValuePair<int, int> temp in MainPage.jointList)
        //    {
        //        switch (temp.Key)
        //        {
        //            case 1:
        //                btnNeck.Background = Brushes.Red;
        //                break;
        //            case 2:
        //                btnLeftShoulder.Background = Brushes.Red;
        //                break;
        //            case 3:
        //                btnRightShoulder.Background = Brushes.Red;
        //                break;
        //            case 4:
        //                btnLeftElbow.Background = Brushes.Red;
        //                break;
        //            case 5:
        //                btnRightElbow.Background = Brushes.Red;
        //                break;
        //            case 6:
        //                btnLeftWrist.Background = Brushes.Red;
        //                break;
        //            case 7:
        //                btnRightWrist.Background = Brushes.Red;
        //                break;
        //            case 9:
        //                btnLeftHip.Background = Brushes.Red;
        //                break;
        //            case 10:
        //                btnRightHip.Background = Brushes.Red;
        //                break;
        //            case 11:
        //                btnLeftKnee.Background = Brushes.Red;
        //                break;
        //            case 12:
        //                btnRightKnee.Background = Brushes.Red;
        //                break;
        //            case 13:
        //                btnLeftAnkle.Background = Brushes.Red;
        //                break;
        //            case 14:
        //                btnRightAnkle.Background = Brushes.Red;
        //                break;
        //        }
        //    }
        //    #endregion
        //}

        //void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        //{
        //    //throw new NotImplementedException();

        //    //Dispatcher.BeginInvoke((Action) =>
        //    //{

        //    //});
        //}

        public static int jointID;    //Selected Joint's ID

        private Button previousButton = null;
        private void ResetPreviousButton(Button btn)
        {
            if (previousButton != null)
            {
                if (previousButton != btn)
                {
                    previousButton.BorderBrush = Brushes.Black;
                }
            }
            previousButton = btn;
        }

        #region joints click
        private void btnNeck_Click(object sender, RoutedEventArgs e)
        {
            jointID = 1;
            lblMaxAngle.Text = "Nil";
            lblMinAngle.Text = "Nil";
            displayJointSeverity();
            btnNeck.BorderBrush = Brushes.White;
            lblJoint.Text = "Neck";
            ResetPreviousButton(btnNeck);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnLeftShoulder_Click(object sender, RoutedEventArgs e)
        {
            jointID = 2;
            #region show MaxMin
            string minX = "";
            string minY = "";
            string minZ = "";
            string maxX = "";
            string maxY = "";
            string maxZ = "";
            int counter = 0;
            bool nill = false;
            foreach (tara_wcf.gamePlay gp in MainPage.gpList)
            {
                if (counter <= 6)
                {
                    if (gp.JointID == jointID)
                    {
                        switch (gp.GameKey)
                        {
                            case "Max Angle X":
                                maxX = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Max Angle Y":
                                maxY = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Max Angle Z":
                                maxZ = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle X":
                                minX = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle Y":
                                minY = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle Z":
                                minZ = gp.GameValue;
                                counter++;
                                break;
                        }
                    }
                }
            }
            if (nill == true)
            {
                lblMaxAngle.Text = Math.Truncate(Convert.ToDouble(maxX)).ToString() + ", " + Math.Truncate(Convert.ToDouble(maxY)).ToString() + ", " + Math.Truncate(Convert.ToDouble(maxZ)).ToString() + "(X, Y, Z)";
                lblMinAngle.Text = Math.Truncate(Convert.ToDouble(minX)).ToString() + ", " + Math.Truncate(Convert.ToDouble(minY)).ToString() + ", " + Math.Truncate(Convert.ToDouble(minZ)).ToString() + "(X, Y, Z)";
            }
            else
            {
                lblMaxAngle.Text = "Nil";
                lblMinAngle.Text = "Nil";
            }
            #endregion
            displayJointSeverity();
            btnLeftShoulder.BorderBrush = Brushes.White;
            lblJoint.Text = "Left Shoulder";
            ResetPreviousButton(btnLeftShoulder);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnRightShoulder_Click(object sender, RoutedEventArgs e)
        {
            jointID = 3;
            #region show MaxMin
            string minX = "";
            string minY = "";
            string minZ = "";
            string maxX = "";
            string maxY = "";
            string maxZ = "";
            int counter = 0;
            bool nill = false;
            foreach (tara_wcf.gamePlay gp in MainPage.gpList)
            {
                if (counter <= 6)
                {
                    if (gp.JointID == jointID)
                    {
                        switch (gp.GameKey)
                        {
                            case "Max Angle X":
                                maxX = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Max Angle Y":
                                maxY = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Max Angle Z":
                                maxZ = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle X":
                                minX = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle Y":
                                minY = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle Z":
                                minZ = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                        }
                    }
                }
            }
            if (nill == true)
            {
                lblMaxAngle.Text = Math.Truncate(Convert.ToDouble(maxX)).ToString() + ", " + Math.Truncate(Convert.ToDouble(maxY)).ToString() + ", " + Math.Truncate(Convert.ToDouble(maxZ)).ToString() + "(X, Y, Z)";
                lblMinAngle.Text = Math.Truncate(Convert.ToDouble(minX)).ToString() + ", " + Math.Truncate(Convert.ToDouble(minY)).ToString() + ", " + Math.Truncate(Convert.ToDouble(minZ)).ToString() + "(X, Y, Z)";
            }
            else
            {
                lblMaxAngle.Text = "Nil";
                lblMinAngle.Text = "Nil";
            }
            #endregion
            displayJointSeverity();
            btnRightShoulder.BorderBrush = Brushes.White;
            lblJoint.Text = "Right Shoulder";
            ResetPreviousButton(btnRightShoulder);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnLeftElbow_Click(object sender, RoutedEventArgs e)
        {
            jointID = 4;
            #region show MaxMin
            string min = "";
            string max = "";
            int counter = 0;
            bool nill = false;
            foreach (tara_wcf.gamePlay gp in MainPage.gpList)
            {
                if (counter <= 2)
                {
                    if (gp.JointID == jointID)
                    {
                        switch (gp.GameKey)
                        {
                            case "Max Angle Z":
                                max = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle Z":
                                min = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                        }
                    }
                }
            }
            if (nill == true)
            {
                lblMaxAngle.Text = Math.Truncate(Convert.ToDouble(max)).ToString() + "(Z)";
                lblMinAngle.Text = Math.Truncate(Convert.ToDouble(min)).ToString() + "(Z)";
            }
            else
            {
                lblMaxAngle.Text = "Nil";
                lblMinAngle.Text = "Nil";
            }
            #endregion
            displayJointSeverity();
            btnLeftElbow.BorderBrush = Brushes.White;
            lblJoint.Text = "Left Elbow";
            ResetPreviousButton(btnLeftElbow);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnRightElbow_Click(object sender, RoutedEventArgs e)
        {
            jointID = 5;
            #region show MaxMin
            string min = "";
            string max = "";
            int counter = 0;
            bool nill = false;
            foreach (tara_wcf.gamePlay gp in MainPage.gpList)
            {
                if (counter <= 2)
                {
                    if (gp.JointID == jointID)
                    {
                        switch (gp.GameKey)
                        {
                            case "Max Angle Z":
                                max = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle Z":
                                min = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                        }
                    }
                }
            }
            if (nill == true)
            {
                lblMaxAngle.Text = Math.Truncate(Convert.ToDouble(max)).ToString() + "(Z)";
                lblMinAngle.Text = Math.Truncate(Convert.ToDouble(min)).ToString() + "(Z)";
            }
            else
            {
                lblMaxAngle.Text = "Nil";
                lblMinAngle.Text = "Nil";
            }
            #endregion
            displayJointSeverity();
            btnRightElbow.BorderBrush = Brushes.White;
            lblJoint.Text = "Right Elbow";
            ResetPreviousButton(btnRightElbow);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnLeftWrist_Click(object sender, RoutedEventArgs e)
        {
            jointID = 6;
            lblMaxAngle.Text = "Nil";
            lblMinAngle.Text = "Nil";
            displayJointSeverity();
            btnLeftWrist.BorderBrush = Brushes.White;
            lblJoint.Text = "Left Wrist";
            ResetPreviousButton(btnLeftWrist);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnRightWrist_Click(object sender, RoutedEventArgs e)
        {
            jointID = 7;
            lblMaxAngle.Text = "Nil";
            lblMinAngle.Text = "Nil";
            displayJointSeverity();
            btnRightWrist.BorderBrush = Brushes.White;
            lblJoint.Text = "Right Wrist";
            ResetPreviousButton(btnRightWrist);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnLeftHip_Click(object sender, RoutedEventArgs e)
        {
            jointID = 9;
            #region show MaxMin
            string minX = "";
            string minZ = "";
            string maxX = "";
            string maxZ = "";
            int counter = 0;
            bool nill = false;
            foreach (tara_wcf.gamePlay gp in MainPage.gpList)
            {
                if (counter <= 4)
                {
                    if (gp.JointID == jointID)
                    {
                        switch (gp.GameKey)
                        {
                            case "Max Angle X":
                                maxX = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Max Angle Z":
                                maxZ = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle X":
                                minX = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle Z":
                                minZ = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                        }
                    }
                }
            }
            if (nill == true)
            {
                lblMaxAngle.Text = Math.Truncate(Convert.ToDouble(maxX)).ToString() + ", " + Math.Truncate(Convert.ToDouble(maxZ)).ToString() + "(X, Z)";
                lblMinAngle.Text = Math.Truncate(Convert.ToDouble(minX)).ToString() + ", " + Math.Truncate(Convert.ToDouble(minZ)).ToString() + "(X, Z)";
            }
            else
            {
                lblMaxAngle.Text = "Nil";
                lblMinAngle.Text = "Nil";
            }
            #endregion
            displayJointSeverity();
            btnLeftHip.BorderBrush = Brushes.White;
            lblJoint.Text = "Left Hip";
            ResetPreviousButton(btnLeftHip);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnRightHip_Click(object sender, RoutedEventArgs e)
        {
            jointID = 10;
            #region show MaxMin
            string minX = "";
            string minZ = "";
            string maxX = "";
            string maxZ = "";
            int counter = 0;
            bool nill = false;
            foreach (tara_wcf.gamePlay gp in MainPage.gpList)
            {
                if (counter <= 4)
                {
                    if (gp.JointID == jointID)
                    {
                        switch (gp.GameKey)
                        {
                            case "Max Angle X":
                                maxX = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Max Angle Z":
                                maxZ = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle X":
                                minX = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle Z":
                                minZ = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                        }
                    }
                }
            }
            if (nill == true)
            {
                lblMaxAngle.Text = Math.Truncate(Convert.ToDouble(maxX)).ToString() + ", " + Math.Truncate(Convert.ToDouble(maxZ)).ToString() + "(X, Z)";
                lblMinAngle.Text = Math.Truncate(Convert.ToDouble(minX)).ToString() + ", " + Math.Truncate(Convert.ToDouble(minZ)).ToString() + "(X, Z)";
            }
            #endregion
            displayJointSeverity();
            btnRightHip.BorderBrush = Brushes.White;
            lblJoint.Text = "Right Hip";
            ResetPreviousButton(btnRightHip);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnLeftKnee_Click(object sender, RoutedEventArgs e)
        {
            jointID = 11;
            #region show MaxMin
            string min = "";
            string max = "";
            int counter = 0;
            bool nill = false;
            foreach (tara_wcf.gamePlay gp in MainPage.gpList)
            {
                if (counter <= 2)
                {
                    if (gp.JointID == jointID)
                    {
                        switch (gp.GameKey)
                        {
                            case "Max Angle Z":
                                max = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle Z":
                                min = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                        }
                    }
                }
            }
            if (nill == true)
            {
                lblMaxAngle.Text = Math.Truncate(Convert.ToDouble(max)).ToString() + "(Z)";
                lblMinAngle.Text = Math.Truncate(Convert.ToDouble(min)).ToString() + "(Z)";
            }
            else
            {
                lblMaxAngle.Text = "Nil";
                lblMinAngle.Text = "Nil";
            }
            #endregion
            displayJointSeverity();
            btnLeftKnee.BorderBrush = Brushes.White;
            lblJoint.Text = "Left Knee";
            ResetPreviousButton(btnLeftKnee);
        }

        private void btnRightKnee_Click(object sender, RoutedEventArgs e)
        {
            jointID = 12;
            #region show MaxMin
            string min = "";
            string max = "";
            int counter = 0;
            bool nill = false;
            foreach (tara_wcf.gamePlay gp in MainPage.gpList)
            {
                if (counter <= 2)
                {
                    if (gp.JointID == jointID)
                    {
                        switch (gp.GameKey)
                        {
                            case "Max Angle Z":
                                max = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                            case "Min Angle Z":
                                min = gp.GameValue;
                                counter++;
                                nill = true;
                                break;
                        }
                    }
                }
            }
            if (nill == true)
            {
                lblMaxAngle.Text = Math.Truncate(Convert.ToDouble(max)).ToString() + "(Z)";
                lblMinAngle.Text = Math.Truncate(Convert.ToDouble(min)).ToString() + "(Z)";
            }
            else
            {
                lblMaxAngle.Text = "Nil";
                lblMinAngle.Text = "Nil";
            }
            #endregion
            displayJointSeverity();
            btnRightKnee.BorderBrush = Brushes.White;
            lblJoint.Text = "Right Knee";
            ResetPreviousButton(btnRightKnee);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnLeftAnkle_Click(object sender, RoutedEventArgs e)
        {
            jointID = 13;
            lblMaxAngle.Text = "Nil";
            lblMinAngle.Text = "Nil";
            displayJointSeverity();
            btnLeftAnkle.BorderBrush = Brushes.White;
            lblJoint.Text = "Left Ankle";
            ResetPreviousButton(btnLeftAnkle);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        private void btnRightAnkle_Click(object sender, RoutedEventArgs e)
        {
            jointID = 14;
            lblMaxAngle.Text = "Nil";
            lblMinAngle.Text = "Nil";
            displayJointSeverity();
            btnRightAnkle.BorderBrush = Brushes.White;
            lblJoint.Text = "Right Ankle";
            ResetPreviousButton(btnRightAnkle);

            MainWindow main = App.Current.MainWindow as MainWindow;
            MainPage page = main.frame1.Content as MainPage;
            page.updateTreatmentList(jointID);
        }

        #endregion

        private void lblSeverity_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            lblSeverity.Visibility = Visibility.Collapsed;
            tbxSeverity.Visibility = Visibility.Visible;
            tbxSeverity.Text = lblSeverity.Text;
        }

        private void tbxSeverity_LostFocus(object sender, RoutedEventArgs e)
        {
            bool updateLocalList = false;
            double Num;
            if (double.TryParse(tbxSeverity.Text, out Num))
            {
                int index = 0;
                //Add new joint with impairment or update joint severity
                svc.addAndUpdateJointProblem(jointID, MainPage.patientID, Convert.ToInt32(tbxSeverity.Text));
                foreach (KeyValuePair<int, int> temp in MainPage.jointList)
                {
                    if (temp.Key.Equals(jointID))
                    {
                        if (Convert.ToInt16(tbxSeverity.Text) != 0)
                        {
                            //Modify the current jointList
                            MainPage.jointList[index] = new KeyValuePair<int, int>(temp.Key, Convert.ToInt16(tbxSeverity.Text));
                            index++;
                            #region change impairment joint to red

                            switch (jointID)
                            {
                                case 1:
                                    btnNeck.Background = Brushes.Red;
                                    break;
                                case 2:
                                    btnLeftShoulder.Background = Brushes.Red;
                                    break;
                                case 3:
                                    btnRightShoulder.Background = Brushes.Red;
                                    break;
                                case 4:
                                    btnLeftElbow.Background = Brushes.Red;
                                    break;
                                case 5:
                                    btnRightElbow.Background = Brushes.Red;
                                    break;
                                case 6:
                                    btnLeftWrist.Background = Brushes.Red;
                                    break;
                                case 7:
                                    btnRightWrist.Background = Brushes.Red;
                                    break;
                                case 9:
                                    btnLeftHip.Background = Brushes.Red;
                                    break;
                                case 10:
                                    btnRightHip.Background = Brushes.Red;
                                    break;
                                case 11:
                                    btnLeftKnee.Background = Brushes.Red;
                                    break;
                                case 12:
                                    btnRightKnee.Background = Brushes.Red;
                                    break;
                                case 13:
                                    btnLeftAnkle.Background = Brushes.Red;
                                    break;
                                case 14:
                                    btnRightAnkle.Background = Brushes.Red;
                                    break;
                            }

                            #endregion
                            updateLocalList = true;
                            break;
                        }
                        else
                        {
                            //From joint from problem
                            if (svc.removeJointProblem(jointID, MainPage.patientDetail.Uid))
                            {
                                //Remove joint from jointList
                                MainPage.jointList.Remove(temp);
                                //reset the joint back to orignial color
                                #region reset joint color
                                BrushConverter bc = new BrushConverter();
                                Brush brush;
                                brush = (Brush)bc.ConvertFrom("#FF00A703");
                                switch (jointID)
                                {
                                    case 1:
                                        btnNeck.Background = brush;
                                        break;
                                    case 2:
                                        btnLeftShoulder.Background = brush;
                                        break;
                                    case 3:
                                        btnRightShoulder.Background = brush;
                                        break;
                                    case 4:
                                        btnLeftElbow.Background = brush;
                                        break;
                                    case 5:
                                        btnRightElbow.Background = brush;
                                        break;
                                    case 6:
                                        btnLeftWrist.Background = brush;
                                        break;
                                    case 7:
                                        btnRightWrist.Background = brush;
                                        break;
                                    case 9:
                                        btnLeftHip.Background = brush;
                                        break;
                                    case 10:
                                        btnRightHip.Background = brush;
                                        break;
                                    case 11:
                                        btnLeftKnee.Background = brush;
                                        break;
                                    case 12:
                                        btnRightKnee.Background = brush;
                                        break;
                                    case 13:
                                        btnLeftAnkle.Background = brush;
                                        break;
                                    case 14:
                                        btnRightAnkle.Background = brush;
                                        break;
                                }
                                #endregion
                                lblSeverity.Text = "0";
                                updateLocalList = true;
                                break;
                            }
                        }
                    }
                }
                //Add a new impairment joint to the MainPage.jointList
                if (updateLocalList == false)
                {
                    MainPage.jointList.Add(new KeyValuePair<int, int>(jointID, Convert.ToInt16(tbxSeverity.Text)));
                    #region change impairment joint to red

                    switch (jointID)
                    {
                        case 1:
                            btnNeck.Background = Brushes.Red;
                            break;
                        case 2:
                            btnLeftShoulder.Background = Brushes.Red;
                            break;
                        case 3:
                            btnRightShoulder.Background = Brushes.Red;
                            break;
                        case 4:
                            btnLeftElbow.Background = Brushes.Red;
                            break;
                        case 5:
                            btnRightElbow.Background = Brushes.Red;
                            break;
                        case 6:
                            btnLeftWrist.Background = Brushes.Red;
                            break;
                        case 7:
                            btnRightWrist.Background = Brushes.Red;
                            break;
                        case 9:
                            btnLeftHip.Background = Brushes.Red;
                            break;
                        case 10:
                            btnRightHip.Background = Brushes.Red;
                            break;
                        case 11:
                            btnLeftKnee.Background = Brushes.Red;
                            break;
                        case 12:
                            btnRightKnee.Background = Brushes.Red;
                            break;
                        case 13:
                            btnLeftAnkle.Background = Brushes.Red;
                            break;
                        case 14:
                            btnRightAnkle.Background = Brushes.Red;
                            break;
                    }

                    #endregion
                    updateLocalList = true;
                }
                lblSeverity.Text = tbxSeverity.Text;
            }
            else
            {
                MessageBox.Show("Severity ranges from 0- 4");
            }
            lblSeverity.Visibility = Visibility.Visible;
            tbxSeverity.Visibility = Visibility.Collapsed;
        }

        private void displayJointSeverity()
        {
            foreach (KeyValuePair<int, int> temp in MainPage.patientDetail.JointSeverity)
            {
                if (temp.Key.Equals(jointID))
                {
                    lblSeverity.Text = temp.Value.ToString();
                    break;
                }
                else
                {
                    lblSeverity.Text = "0";
                }
            }
        }
    }
}